package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.dto.DishDto;
import com.itheima.service.OrderDetailService;
import com.itheima.service.OrdersService;
import com.itheima.vo.OrderVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrdersService ordersService;

    @Autowired
    private OrderDetailService orderDetailService;

    /**
     * 启用禁用菜品
     * @param map
     * @return
     */
    @PutMapping
    public R<String> updateState(@RequestBody Map map){
        log.info("---修改订单状态:{}----",map);
        ordersService.updateState(map);
        return  R.success("状态修改成功");
    }

    /**
     * 订单的分页查找
     *
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public R<Page<OrderVo>> selectPage(String beginTime,String endTime,String number,int page,int pageSize) {
        List<OrderVo> dtoList = ordersService.selectPage(number,page, pageSize);
//        //查询总记录数
//        long dishCount= dishService.getCountByName(name);

        //组装数据
        Page<OrderVo> dtoPage = new Page<>();

        dtoPage.setSize(pageSize);
        dtoPage.setCurrent(page);
        dtoPage.setRecords(dtoList);


        return R.success(dtoPage);
    }



}
